#ifndef SEQLIST_H
#define SEQLIST_H
#include<cassert>
#include<iostream>
#define Assert(cond,msg)\
    do{\
        if(!(cond)){\
            std ::cerr<<"提示:"<<msg<<std::endl;\
        }\
    }while(0)

using namespace std;
template<typename E>
class AList
{
private:
    int MaxSize;
    int listSize;
    int curr;
    E* listArray;
public:
    AList(int size=100){
        MaxSize = size;
        listSize = 0;
        curr = 0;
        listArray = new E[MaxSize];
    }
    ~AList(){
        delete listArray;
    }

    void clear(){
        delete listArray;
        listSize = 0;
        curr = 0;
        listArray = new E[MaxSize];
    }
    //insert "it" at current position
    void insert(const E& it){
        Assert(listSize<MaxSize,"List capacity exceeded");
        for(int i=listSize;i>curr;i--){
            listArray[i] = listArray[i-1];
        listArray[curr] = it;
        listSize++;
        }
    }
    void append(const E& it){
        Assert(listSize<MaxSize,"List capacity exceeded");
        listArray[listSize++] = it;
    }
    E remove(){
        Assert((curr>=0)&&curr<=listSize,"No element");
        E it = listArray[curr];
        for(int i = curr;i<listSize-1;i++){
            listArray[i] = listArray[i+1];
        listSize--;
        }
        return it;
    }
    void moveToStart(){curr = 0;}
    void moveToEnd(){curr = listSize-1;}
    void prev(){if (curr!=0) curr--;}
    void next(){if(curr<listSize-1)curr++;}
    //return listSize
    int length() const {return listSize;}
    //return current position
    int currpos() const {return curr;}
    //set current list position to "pos"
    void moveToPos(int pos){
        Assert ((pos>=0&&pos<=listSize-1),"pos out of range");
        curr = pos;
    }
    const E& getValue(){
        Assert((curr>=0&&curr<listSize),"No current element");
        return listArray[curr];
    }
};
#endif
